# -*- codeing = utf-8 -*-
# @Time : 2021/10/9 20:54
# @Author : xiaow
# @File : wordcloudutil.py
# @Software : PyCharm


from wordcloud import WordCloud
import PIL.Image as image
import numpy as np

import jieba


def trans_CN(text):
    # 接收分词的字符串
    word_list = jieba.cut(text)
    # 分词后在单独个体之间加上空格
    result = " ".join(word_list)
    return result


def getWordCloud(text):
    # print(text)
    text = trans_CN(text)
    # 词云背景图
    mask = np.array(image.open("E://file//pics//1.png"))
    wordcloud = WordCloud(
        mask=mask,
        # 字体样式文件
        font_path="C:\Windows\Fonts\STXINGKA.TTF",
        background_color='white'
    ).generate(text)
    image_produce = wordcloud.to_image()
    image_produce.show()
